home *** CD-ROM | disk | FTP | other *** search
- #! /bin/sh
- # This is a shell archive, meaning:
- # 1. Remove everything above the #! /bin/sh line.
- # 2. Save the resulting text in a file.
- # 3. Execute the file with /bin/sh (not csh) to create:
- # filter80.c
- # makefile
- # readme
- # sgexe.c
- # sgl.l
- # sgy.y
- # This archive created: Fri Apr 3 21:06:02 1992
- export PATH; PATH=/bin:/usr/bin:$PATH
- if test -f 'filter80.c'
- then
- echo shar: "will not over-write existing file 'filter80.c'"
- else
- cat << \SHAR_EOF > 'filter80.c'
- /* FILTER80.C
- Compile with "cc -o filter80 filter80.c"
- The execute-able file is then "filter80"...
- Run the program with "filter80 <inputfile>"
- The file "<inputfile>" must be in the default directory... i.e. "."
- */
- #include <stdio.h>
- #include <ctype.h>
- main (argc, argv)
- int argc;
- char **argv;
- {
- int linecnt=0;
- int MAXCOL=70;
- char achar;
- FILE *pfile;
- FILE *fopen();
-
- if ( argc <= 1 ) {
- printf( "Strip all control characters from a file.\n");
- printf( "USAGE: %s <inputfile>\n", argv[0] );
- exit(0);
- }
-
- pfile = fopen( argv[1], "r" ); /*open for read only*/
- if ( pfile == NULL ) {
- printf( "FOPEN of %s failed!!\n", argv[1] );
- exit(0);
- }
- achar = EOF+1; /*Initialize so-as not = EOF*/
-
- while (achar != EOF) {
- achar = getc( pfile );
-
- /* strip control char's and limit lines to MAXCOL (80?) */
- if( ! iscntrl(achar) && achar != EOF ) {
- linecnt++;
- switch( achar ) {
- case ';':
- case '(':
- case '[':
- if( linecnt > (MAXCOL) ) {
- linecnt = 0;
- printf( "\n" );
- } /*end if*/
- break;
- } /*end switch*/
-
- printf( "%c", achar );
-
- switch( achar ) {
- case ')':
- case ' ':
- case ']':
- if( linecnt > (MAXCOL) ) {
- linecnt = 0;
- printf( "\n" );
- } /*end if*/
- break;
- } /*end switch*/
- } else {
- switch( achar ) {
- case '\n':
- linecnt = 0;
- printf( "%c", achar );
- break;
- case '\t':
- printf( "%c", achar );
- break;
- } /*end switch*/
- } /*end if-else*/
- } /*end while*/
- } /*end main*/
- SHAR_EOF
- fi
- if test -f 'makefile'
- then
- echo shar: "will not over-write existing file 'makefile'"
- else
- cat << \SHAR_EOF > 'makefile'
- # makefile for building c objects and linking c program for LEX
-
-
- # ALL modules
-
- all: sgexe filter80
-
- # LEX/YACC modules
-
- filter80: filter80.o
- cc -o filter80 filter80.o
-
- sgexe: sgexe.o y.tab.o lex.yy.o
- cc -o sgexe sgexe.o y.tab.o lex.yy.o
-
- sgexe.o: sgexe.c
-
- lex.yy.o: lex.yy.c y.tab.h
-
- lex.yy.c: sgl.l
- lex sgl.l
-
- sgy.o: sgy.c
-
- y.tab.o: y.tab.c
-
- y.tab.c: sgy.y
- yacc -d sgy.y
- SHAR_EOF
- fi
- if test -f 'readme'
- then
- echo shar: "will not over-write existing file 'readme'"
- else
- cat << \SHAR_EOF > 'readme'
- Here are some files that I hacked out while working on a
- Neural Network Go playing program.
-
- This may be a start for anyone needing to parse the Smart-Go format.
-
- NOTICE: THIS IS NOT A SMART-GO GRAMMAR DEFINITION.
-
- I started from a formal definition of the Smart-Go format.
- However, I changed the grammar, as necessary, to parse actual games.
- Additionally, the grammar was simplified if particular commands or
- parameters were not needed for my application. This particular
- parser performs no usefull function, since I backed out most
- of my 'user defined' C code.
-
- Filter80 is a simple program to truncate the possibly long lines
- in the Smart-Go format. This parser will choke on long lines. Long
- in this case is defined to be something over 80, probably around 250.
-
- The following are some listings and 'sum's on this UNIX machine.
-
- long listing:
-
- -rw------- 1 jconley 1508 Mar 1 00:08 filter80.c
- -rw------- 1 jconley 386 Apr 3 23:11 makefile
- -rw------- 1 jconley 558 Apr 1 16:39 sgexe.c
- -rw------- 1 jconley 5637 Apr 3 22:55 sgl.l
- -rw------- 1 jconley 5392 Apr 3 22:54 sgy.y
-
- sum *:
-
- 40985 2 filter80.c
- 38372 1 makefile
- 59209 1 sgexe.c
- 35757 6 sgl.l
- 09611 6 sgy.y
- SHAR_EOF
- fi
- if test -f 'sgexe.c'
- then
- echo shar: "will not over-write existing file 'sgexe.c'"
- else
- cat << \SHAR_EOF > 'sgexe.c'
- /*
- * Copyright 1988, 1989 Mortice Kern Systems Inc.
- * All rights reserved.
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
-
- #define FALSE 0
- #define TRUE 1
-
- #ifndef YYSTYPE
- #define YYSTYPE int
- #endif
-
- YYSTYPE yylval; /* yylex() sets this */
- int yylineno;
-
- int errcnt; /* used in yyparse */
- int sglevel; /* used in yyparse */
- int gamecnt; /* used in yyparse */
- FILE *fpm; /* used in sgy.y */
- int PRINTOFF; /* used in sgy.y */
-
- main()
- {
- int lexrtn;
-
- errcnt = 0;
- printf( "Calling yyparse()\n" );
- lexrtn = yyparse();
-
- exit();
- }
- SHAR_EOF
- fi
- if test -f 'sgl.l'
- then
- echo shar: "will not over-write existing file 'sgl.l'"
- else
- cat << \SHAR_EOF > 'sgl.l'
- D [0-9]
- coord [a-t]
-
- %{
- /* DEFN - sgl.l Smart-Go lexicon */
- #include <stdio.h>
- #include "y.tab.h"
-
- /* void count( void ); Prototype */
- #undef YYLMAX
- #define YYLMAX 2048
- #undef output(c)
- #define output(c) /* no output from from yacc/lex */
-
- int column; /* Global variable used in the function count() */
- %}
-
- %%
- {D}+ { count(); return(NUMBER); }
- {D}*"."{D}+ { count(); return(REALNUM); }
-
- \"(\\.|[^\\"])*\" { count(); return(STRING); }
-
- {coord}{coord} { count(); return(POINT); }
-
- "?" { count(); return('?'); }
- ":" { count(); return(':'); }
- ";" { count(); return(';'); }
- "(" { count(); return('('); }
- ")" { count(); return(')'); }
- "[" { count(); return('['); }
- "]" { count(); return(']'); }
- "-" { count(); return('-'); }
- "+" { count(); return('+'); }
-
- "AB" { count(); return(AB); }
- "AddBlack" { count(); return(AB); }
- "AE" { count(); return(AE); }
- "AddEmpty" { count(); return(AE); }
- "AN" { count(); return(AN); }
- "AW" { count(); return(AW); }
- "AddWhite" { count(); return(AW); }
- "B" { count(); return(B); }
- "Black" { count(); return(B); }
- "BL" { count(); return(BL); }
- "BlackLeft" { count(); return(BL); }
- "BM" { count(); return(BM); }
- "BadMove" { count(); return(BM); }
- "BR" { count(); return(BR); }
- "BlackRank" { count(); return(BR); }
- "BS" { count(); return(BS); }
- "BlackSpec" { count(); return(BS); }
- "C" { count(); return(C); }
- "Comment" { count(); return(C); }
- "CH" { count(); return(CH); }
- "CHeck" { count(); return(CH); }
- "CM" { count(); return(CM); }
- "CP" { count(); return(CP); }
- "DG" { count(); return(DG); }
- "DT" { count(); return(DT); }
- "DaTe" { count(); return(DT); }
- "EG" { count(); return(EG); }
- "EL" { count(); return(EL); }
- "EvaLuation" { count(); return(EL); }
- "EV" { count(); return(EV); }
- "EVent" { count(); return(EV); }
- "EX" { count(); return(EX); }
- "EXpected" { count(); return(EX); }
- "FF" { count(); return(FF); }
- "FileFormat" { count(); return(FF); }
- "FG" { count(); return(FG); }
- "FiGure" { count(); return(FG); }
- "GB" { count(); return(GB); }
- "GoodBlack" { count(); return(GB); }
- "GC" { count(); return(GC); }
- "GameComment" { count(); return(GC); }
- "GM" { count(); return(GM); }
- "GaMe" { count(); return(GM); }
- "GN" { count(); return(GN); }
- "GameName" { count(); return(GN); }
- "GW" { count(); return(GW); }
- "GoodWhite" { count(); return(GW); }
- "HA" { count(); return(HA); }
- "HAndicap" { count(); return(HA); }
- "HO" { count(); return(HO); }
- "KI" { count(); return(KI); }
- "KomI" { count(); return(KI); }
- "KM" { count(); return(KI); }
- "KoMi" { count(); return(KI); }
- "L" { count(); return(L); }
- "Letter" { count(); return(L); }
- "LB" { count(); return(LB); }
- "LaBel" { count(); return(LB); }
- "M" { count(); return(M); }
- "Mark" { count(); return(M); }
- "N" { count(); return(N); }
- "Node" { count(); return(N); }
- "Name" { count(); return(N); }
- "NB" { count(); return(NB); }
- "NW" { count(); return(NW); }
- "OE" { count(); return(OE); }
- "ON" { count(); return(ON); }
- "OS" { count(); return(OS); }
- "PB" { count(); return(PB); }
- "PlayerBlack" { count(); return(PB); }
- "PC" { count(); return(PC); }
- "PlaCe" { count(); return(PC); }
- "PL" { count(); return(PL); }
- "PLayer" { count(); return(PL); }
- "PW" { count(); return(PW); }
- "PlayerWhite" { count(); return(PW); }
- "RE" { count(); return(RE); }
- "REsult" { count(); return(RE); }
- "RG" { count(); return(RG); }
- "ReGion" { count(); return(RG); }
- "RO" { count(); return(RO); }
- "ROund" { count(); return(RO); }
- "SC" { count(); return(SC); }
- "SeCure" { count(); return(SC); }
- "SL" { count(); return(SL); }
- "SeLected" { count(); return(SL); }
- "SO" { count(); return(SO); }
- "SOurce" { count(); return(SO); }
- "SZ" { count(); return(SZ); }
- "SiZe" { count(); return(SZ); }
- "Size" { count(); return(SZ); }
- "TB" { count(); return(TB); }
- "TerritoryBlack" { count(); return(TB); }
- "TC" { count(); return(TC); }
- "TE" { count(); return(TE); }
- "TEsuji" { count(); return(TE); }
- "TM" { count(); return(TM); }
- "TiMe" { count(); return(TM); }
- "TR" { count(); return(TR); }
- "TW" { count(); return(TW); }
- "TerritoryWhite" { count(); return(TW); }
- "US" { count(); return(US); }
- "USer" { count(); return(US); }
- "V" { count(); return(V); }
- "Value" { count(); return(V); }
- "VW" { count(); return(VW); }
- "VieW" { count(); return(VW); }
- "W" { count(); return(W); }
- "White" { count(); return(W); }
- "WL" { count(); return(WL); }
- "WhiteLeft" { count(); return(WL); }
- "WR" { count(); return(WR); }
- "WhiteRank" { count(); return(WR); }
- "WS" { count(); return(WS); }
- "WhiteSpec" { count(); return(WS); }
-
- "A" { count(); return(MARKER); }
- "D" { count(); return(MARKER); }
- "E" { count(); return(MARKER); }
- "F" { count(); return(MARKER); }
- "G" { count(); return(MARKER); }
- "H" { count(); return(MARKER); }
- "I" { count(); return(MARKER); }
- "J" { count(); return(MARKER); }
- "K" { count(); return(MARKER); }
- "O" { count(); return(MARKER); }
- "P" { count(); return(MARKER); }
- "Q" { count(); return(MARKER); }
- "R" { count(); return(MARKER); }
- "S" { count(); return(MARKER); }
- "T" { count(); return(MARKER); }
- "U" { count(); return(MARKER); }
- "X" { count(); return(MARKER); }
- "Y" { count(); return(MARKER); }
- "Z" { count(); return(MARKER); }
-
- \\. { count(); return(UNKNOWN); }
- . { count(); return(UNKNOWN); }
- %%
-
-
- yywrap()
- {
- return(1);
- }
-
-
- int count()
- {
- int i;
-
- for (i = 0; yytext[i] != '\0'; i++)
- if (yytext[i] == '\n')
- column = 0;
- else if (yytext[i] == '\t')
- column += 8 - (column % 8);
- else
- column++;
-
- /*ECHO;*/
- } /*end count()*/
- SHAR_EOF
- fi
- if test -f 'sgy.y'
- then
- echo shar: "will not over-write existing file 'sgy.y'"
- else
- cat << \SHAR_EOF > 'sgy.y'
- /* CCAGO */
- /* This YACC file reads any Smart-Go game record. */
- /* Only a few moves are important and passed on to the output. */
- /* These moves are Black/White moves and any stone placements. */
- /* The idea here is an intermediate step for trimming down a game record */
- /* to only the important moves, for the CCAGO system. */
- /* */
- %token UNKNOWN STRING REALNUM NUMBER POINT MARKER
- %token B W C N V CH GB GW TE BM BL WL FG AB AW AE PL GN GC EV RO
- %token DT PC PB PW RE US TM SO RO TB TW SC RG EL EX SL M L
- %token GM SZ VW BS WS BR WR HA ON TC LB HO TR DG
-
- %token KI FF CP AN OE OS CM NB NW EG
- %start init
-
- %{
- /* CCAGO stuff */
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
-
- #define FALSE 0
- #define TRUE 1
- extern int PRINTOFF;
- extern int errcnt;
- extern int sglevel;
- extern int gamecnt;
- /* end CCAGO stuff */
- %}
-
- %%
-
- init
- : { gamecnt=0;
- PRINTOFF=FALSE; }
- collection
- ;
-
- collection
- : { printf("\nCollection start\n"); }
- gametree collection
- | /*null*/
- ;
-
- gametree
- : '(' { gamecnt++;
- sglevel=1;
- printf("\nNew Game%d\n", gamecnt );
- printf("\n%s", yytext );
- }
- sequence ')' { sglevel=0;
- printf("\nEnd Game%d\n", gamecnt );
- printf("%s\n", yytext );
- }
- ;
-
- sequence
- : sequence node
- | /*null*/
- ;
-
- node
- : ';' proplist
- | variation
- ;
-
- variation
- : '(' { sglevel++;
- printf("\nLevel=%d\n", sglevel );
- printf("\n%s", yytext );
- }
- sequence ')' { sglevel--;
- printf("\nLevel=%d\n", sglevel );
- printf("%s\n", yytext );
- }
- ;
-
- proplist
- : proplist property
- | /*null*/
- ;
-
- pointlist
- : /*null*/
- | '[' { if(!PRINTOFF)
- printf("%s", yytext ); }
- apoint
- ']' { if(!PRINTOFF)
- printf("%s", yytext ); }
- pointlist
- ;
-
- apoint
- : POINT { if(!PRINTOFF)
- printf("%s", yytext ); }
- | num
- | error
- ;
-
- labellist
- : '[' POINT ':' marker ']' labellist
- | '[' POINT ':' marker ']'
- | '[' error ']'
- ;
-
- marker
- : MARKER
- | B
- | C
- | L
- | M
- | N
- | V
- | W
- | UNKNOWN
- ;
-
- textval
- : error
- | /*null*/
- ;
-
- moveval
- : POINT
- | /*null*/
- ;
-
- tripleval
- : inumval
- ;
-
- colorval
- : B
- | W
- ;
-
- inumval
- : num { $$ = $1; }
- | '+' num { $$ = $2; }
- | '-' num { $$ = 0 - $2; }
- ;
-
- realval
- : num { $$ = $1; }
- | '+' num { $$ = $2; }
- | '-' num { $$ = 0 - $2; }
- ;
-
- num
- : REALNUM { $$ = atof(yytext); }
- | NUMBER { $$ = atoi(yytext); }
- | '?' { $$ = 0; }
- | /*null*/
- ;
-
- property
- : AB { printf(";B"); }
- pointlist
- | AE { printf(";AE"); }
- pointlist
- | AN '[' textval ']'
- | AW { printf(";W"); }
- pointlist
- | B { printf(";B"); }
- pointlist
- | BL '[' realval ']'
- | BM '[' tripleval ']'
- | BR '[' textval ']'
- | BS '[' textval ']'
- | C '[' textval ']'
- | CH '[' tripleval ']'
- | CM '[' textval ']'
- | CP '[' textval ']'
- | DG '[' ']'
- | DT '[' textval ']'
- | EG { PRINTOFF = TRUE; } /* ?? */
- pointlist
- { PRINTOFF = FALSE; }
- | EL '[' inumval ']'
- | EV '[' textval ']'
- | EX '[' moveval ']'
- | FF '[' textval ']'
- | FG '[' ']'
- | GB '[' tripleval ']'
- | GC '[' textval ']'
- | GM '[' inumval ']'
- | GN '[' textval ']'
- | GW '[' tripleval ']'
- | HA '[' inumval ']' { switch( $3 ){
- /* verify case 1: !! */
- case 9: printf(";B[jj]");
- case 8: printf(";B[dj]");
- printf(";B[pj]");
- case 6: printf(";B[jd]");
- printf(";B[jp]");
- case 4: printf(";B[dj]");
- case 3: printf(";B[po]");
- case 2: printf(";B[pp]");
- case 1: printf(";B[pd]");
- break;
- case 7: printf(";B[jd]");
- printf(";B[jp]");
- case 5: printf(";B[jj]");
- printf(";B[dd]");
- printf(";B[dp]");
- printf(";B[pd]");
- printf(";B[pp]");
- break;
- }/*end switch*/
- }/*end code*/
- | HO '[' ']'
- | KI '[' textval ']' /*komi*/
- | L { PRINTOFF = TRUE; } /*letters points */
- pointlist
- { PRINTOFF = FALSE; }
- | LB labellist /*label*/
- | M { PRINTOFF=TRUE; } /* Mark?? */
- pointlist
- { PRINTOFF=FALSE; }
- | N '[' textval ']' /*node*/
- | NB '[' inumval ']'
- | NW '[' inumval ']'
- | OE '[' textval ']'
- | ON '[' textval ']'
- | OS '[' textval ']'
- | PB '[' textval ']'
- | PC '[' textval ']'
- | PL '[' colorval ']'
- | PW '[' textval ']'
- | RE '[' textval ']'
- | RG { PRINTOFF=TRUE; } /* ReGion */
- pointlist
- { PRINTOFF=FALSE; }
- | RO '[' textval ']'
- | SC { PRINTOFF=TRUE; } /* SeCure?? */
- pointlist
- { PRINTOFF=FALSE; }
- | SL { PRINTOFF=TRUE; } /* SeLect?? */
- pointlist
- { PRINTOFF=FALSE; }
- | SO '[' textval ']'
- | SZ '[' inumval ']'
- | TB { PRINTOFF=TRUE; } /* TerrBlack */
- pointlist
- { PRINTOFF=FALSE; }
- | TC '[' inumval ']'
- | TE '[' tripleval ']'
- | TM '[' textval ']'
- | TR { PRINTOFF=TRUE; } /* ?? */
- pointlist
- { PRINTOFF=FALSE; }
- | TW { PRINTOFF=TRUE; } /* TerrWhite */
- pointlist
- { PRINTOFF=FALSE; }
- | US '[' textval ']'
- | V '[' inumval ']'
- | VW { PRINTOFF=TRUE; } /* VieW?? */
- pointlist
- { PRINTOFF=FALSE; }
- | W { printf(";W"); }
- pointlist
- | WL '[' realval ']'
- | WR '[' textval ']'
- | WS '[' textval ']'
- | UNKNOWN '[' textval ']' {printf("\nUNKNOWN Command\n");}
- ;
- %%
-
- #include <stdio.h>
-
- #undef YYSSIZE
- #define YYSSIZE 2048
-
- #define YYSTATIC
-
- extern char yytext[];
- extern int column;
-
- yyerror(s)
- char *s;
- {
- fflush(stdout);
- errcnt++;
- printf("\nError %s count=%d col=%d\n", s, errcnt, column);
- }
- SHAR_EOF
- fi
- exit 0
- # End of shell archive
-